home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 823 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: stern.fokus.gmd.de!news
  2. From: Watson <sayegh@fokus.gmd.de>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: To malloc (new) or not to malloc?  When is the question.
  5. Date: Tue, 09 Jan 1996 17:54:32 +0100
  6. Organization: GMD FOKUS - Research Institute for Open Communication Systems
  7. Message-ID: <30F29DC8.49C@fokus.gmd.de>
  8. References: <4ctvk3$ort@maverick.tad.eds.com>
  9. NNTP-Posting-Host: pollux.fokus.gmd.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b4 (X11; I; SunOS 5.4 sun4m)
  14.  
  15. Darrin Smith wrote:
  16.  
  17. >         struct st1{char one[10];
  18. >                    char two[20];
  19. >                    char three[10];
  20. >                   };
  21. >         st1 *sptr;      //or struct st1 *sptr in C instead of C++
  22. >         sptr=fread(....);
  23. > This caused a program I was trying to debug to crash.  When I allocated
  24. > memory for sptr (I used sptr=new st1; but I suppose malloc would have done
  25. > just as well) it worked fine.
  26.  
  27. fread() does not *return* the data but the size of the data. sptr has
  28. to be given as a parameter. 
  29. -- 
  30. *    Greetinx,
  31.     Watson (sayegh@fokus.gmd.de)
  32.     more personal details at:
  33.     http://www.fokus.gmd.de/ovma/employees/sayegh/entry.html
  34.